<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;

use User\Api\UserApi as UserApi;

/**
 * 后台首页控制器
 *
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class BetController extends AdminController {

	/**
	 * 下注活动列表
	 *
	 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
	 */
	public function index() {
        $this->meta_title = '下注列表';

        if ( isset($_GET['time-start']) ) {
            $where['add_time'][] = array('egt',strtotime(I('time-start')));
            $this->assign('time-start',I('time-start'));
        }
        if ( isset($_GET['time-end']) ) {
            $where['add_time'][] = array('elt',24*60*60 + strtotime(I('time-end')));
            $this->assign('time-end',I('time-end'));
        }
        if(isset($_GET['periods'])){
            $where['periods']=I('get.periods','','intval');
            $this->assign('periods',I('get.periods'));
        }
        if(isset($_GET['type'])){
            $where['type']=I('get.type','','intval');
            $this->assign('type',I('get.type'));
        }
        if(isset($_GET['nickname'])){
            $condition2['nickname']=array('like','%'.I('get.nickname','','trim').'%');
            $user_list=M('follow')->field('id')->where($condition2)->select();
            $uid='';
            foreach($user_list as $key=>$val){
                $uid.=$val['id'].',';
            }
            $where['user_id']=array('in',trim($uid,','));
            $this->assign('nickname',I('get.nickname','','trim'));
        }
        $total        =  D('rose_buy')->where($where)->count();
        $listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
        $page = new \Think\Page($total, $listRows, $REQUEST);
        $limit=$page->firstRow.','.$page->listRows;

        $list=D('rose_buy')->where($where)->order('id desc')->limit($limit)->select();
        if($total>$listRows){
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        }
        $p =$page->show();
        $this->assign('_page', $p? $p: '');
        $this->assign('_total',$total);
        $this->list=$list;
        $this->display();
	}

    /**
     * 删除猜涨跌活动列表
     */
    public function del(){
        $id     =   I('id','');
        if(empty($id)){
            return false;
        }
        $id=is_array($id)?join(',',$id):$id;
        $date['id']=array('in',$id);
        if(D('rose_buy')->where($date)->delete()){
            $this->success('删除成功', U('Bet/index'));
        }else{
            $this->error(D('rose_buy')->getError());
        }
    }
}
